import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

// 用户路由
export const userAsyncRoutes = [
  {
    path: '/',
    name: 'index',
    title: '首页',
    component: () => import('@/views/user/index'),
    hidden: true
  },
  {
    path: '/services-list',
    name: 'services-list',
    title: '服务列表',
    component: () => import('@/views/user/services/index'),
    hidden: true
  },
  {
    path: '/services-details/:id(\\d+)',
    name: 'services-details',
    title: '服务详情',
    component: () => import('@/views/user/services/details'),
    hidden: true
  },
  {
    path: '/commodity-list',
    name: 'commodity-list',
    title: '产品列表',
    component: () => import('@/views/user/commodity/index'),
    hidden: true
  },
  {
    path: '/commodity-details/:id(\\d+)',
    name: 'commodity-details',
    title: '产品详情',
    component: () => import('@/views/user/commodity/details'),
    hidden: true
  },
  {
    path: '/information-list',
    name: 'information-list',
    title: '资讯列表',
    component: () => import('@/views/user/information/index'),
    hidden: true
  },
  {
    path: '/information-details/:id(\\d+)',
    name: 'information-details',
    title: '资讯详情',
    component: () => import('@/views/user/information/details'),
    hidden: true
  },
  {
    path: '/notice-list',
    name: 'notice-list',
    title: '公告列表',
    component: () => import('@/views/user/notice/index'),
    hidden: true
  },
  {
    path: '/notice-details/:id(\\d+)',
    name: 'notice-details',
    title: '公告详情',
    component: () => import('@/views/user/notice/details'),
    hidden: true
  },
  {
    path: '/leaves-add',
    name: 'leaves-add',
    title: '留言反馈',
    component: () => import('@/views/user/leaves/add'),
    hidden: true
  },
  {
    path: '/personal',
    name: 'personal',
    title: '个人资料',
    component: () => import('@/views/user/personal/index'),
    hidden: true
  },
  {
    path: '/password',
    name: 'password',
    title: '重置密码',
    component: () => import('@/views/user/password/index'),
    hidden: true
  },
  {
    path: '/appointment',
    name: 'appointment',
    title: '我的预约',
    component: () => import('@/views/user/appointment/manage'),
    hidden: true
  },
  {
    path: '/commodityOrders',
    name: 'commodityOrders',
    title: '我的订单',
    component: () => import('@/views/user/commodityOrders/manage'),
    hidden: true
  },
  {
    path: '/servicesComment',
    name: 'servicesComment',
    title: '我的评价',
    component: () => import('@/views/user/servicesComment/manage'),
    hidden: true
  },
  {
    path: '/leaves',
    name: 'leaves',
    title: '我的留言',
    component: () => import('@/views/user/leaves/manage'),
    hidden: true
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/home', hidden: true }
]

// 连锁店路由
export const staffAsyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
      path: 'home',
      name: 'Home',
      component: () => import('@/views/sys/home/index'),
      meta: { title: '首页', icon: 'el-icon-s-home', affix: true }
    }]
  },

  {
    path: '/sys-personal',
    component: Layout,
    meta: { title: '个人信息', icon: 'el-icon-setting' },
    hidden: true,
    children: [
      {
        path: 'personal',
        name: 'personal',
        component: () => import('@/views/sys/personal/index'),
        meta: { title: '个人资料',  }
      },
      {
        path: 'password',
        name: 'password',
        component: () => import('@/views/sys/password/index'),
        meta: { title: '重置密码',  }
      }
    ]
  },

  {
    path: '/sys-services',
    component: Layout,
    meta: { title: '服务管理', icon: 'el-icon-bank-card', roles: ['5'] },
    children: [
      {
        path: 'services',
        name: 'services',
        component: () => import('@/views/staff/services/index'),
        meta: { title: '服务管理',  },
      },
      {
        path: 'services/add',
        name: 'add',
        component: () => import('@/views/staff/services/add'),
        meta: { title: '添加服务',  },
        hidden: true
      },
      {
        path: 'services/edit/:id(\\d+)',
        name: 'edit',
        component: () => import('@/views/staff/services/edit'),
        meta: { title: '编辑服务',  },
        hidden: true
      },
      {
        path: 'services/details/:id(\\d+)',
        name: 'edit',
        component: () => import('@/views/staff/services/details'),
        meta: { title: '服务详情',  },
        hidden: true
      },
      {
        path: 'appointment',
        name: 'appointment',
        component: () => import('@/views/staff/appointment/index'),
        meta: { title: '订单管理',  },
      },
      {
        path: 'servicesComment',
        name: 'servicesComment',
        component: () => import('@/views/staff/servicesComment/index'),
        meta: { title: '评价管理',  },
      },
    ]
  },

  {
    path: '/sys-commodity',
    component: Layout,
    meta: { title: '产品管理', icon: 'el-icon-eleme', roles: ['5'] },
    children: [
      {
        path: 'commodity',
        name: 'commodity',
        component: () => import('@/views/staff/commodity/index'),
        meta: { title: '产品管理',  }
      },
      {
        path: 'commodity/add',
        name: 'add',
        component: () => import('@/views/staff/commodity/add'),
        meta: { title: '添加产品',  },
        hidden: true
      },
      {
        path: 'commodity/edit/:id(\\d+)',
        name: 'edit',
        component: () => import('@/views/staff/commodity/edit'),
        meta: { title: '编辑产品',  },
        hidden: true
      },
      {
        path: 'commodity/details/:id(\\d+)',
        name: 'edit',
        component: () => import('@/views/staff/commodity/details'),
        meta: { title: '产品详情',  },
        hidden: true
      },
      {
        path: 'commodityOrders',
        name: 'commodityOrders',
        component: () => import('@/views/staff/commodityOrders/index'),
        meta: { title: '兑换管理',  }
      },
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/home', hidden: true }
]

// 管理员路由
export const sysAsyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
      path: 'home',
      name: 'Home',
      component: () => import('@/views/sys/home/index'),
      meta: { title: '首页', icon: 'el-icon-s-home', affix: true }
    }]
  },

  {
    path: '/sys-personal',
    component: Layout,
    meta: { title: '个人信息', icon: 'el-icon-setting' },
    hidden: true,
    children: [
      {
        path: 'personal',
        name: 'personal',
        component: () => import('@/views/sys/personal/index'),
        meta: { title: '个人资料',  }
      },
      {
        path: 'password',
        name: 'password',
        component: () => import('@/views/sys/password/index'),
        meta: { title: '重置密码',  }
      }
    ]
  },

  {
    path: '/sys-user',
    component: Layout,
    meta: { title: '用户管理', icon: 'el-icon-user', roles: ['5'] },
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/sys/user/index'),
        meta: { title: '用户管理',  }
      },
      {
        path: 'staff',
        name: 'staff',
        component: () => import('@/views/sys/staff/index'),
        meta: { title: '连锁店管理',  }
      },
      {
        path: 'admin',
        name: 'admin',
        component: () => import('@/views/sys/admin/index'),
        meta: { title: '管理员管理',  }
      }
    ]
  },

  {
    path: '/sys-basics',
    component: Layout,
    meta: { title: '基础管理', icon: 'el-icon-notebook-2', roles: ['5'] },
    children: [
      {
        path: 'banner',
        name: 'banner',
        component: () => import('@/views/sys/banner/index'),
        meta: { title: '轮播图管理',  }
      },
      {
        path: 'banner/add',
        name: 'add',
        component: () => import('@/views/sys/banner/add'),
        meta: { title: '添加轮播图',  },
        hidden: true
      },
      {
        path: 'banner/edit/:id(\\d+)',
        name: 'edit',
        component: () => import('@/views/sys/banner/edit'),
        meta: { title: '编辑轮播图',  },
        hidden: true
      },
      {
        path: 'about',
        name: 'about',
        component: () => import('@/views/sys/about/index'),
        meta: { title: '关于我们管理',  }
      },
      {
        path: 'about/add',
        name: 'add',
        component: () => import('@/views/sys/about/add'),
        meta: { title: '添加关于我们',  },
        hidden: true
      },
      {
        path: 'about/edit/:id(\\d+)',
        name: 'edit',
        component: () => import('@/views/sys/about/edit'),
        meta: { title: '编辑关于我们',  },
        hidden: true
      },
      {
        path: 'links',
        name: 'links',
        component: () => import('@/views/sys/links/index'),
        meta: { title: '友情链接管理',  }
      },
      {
        path: 'levels',
        name: 'levels',
        component: () => import('@/views/sys/levels/index'),
        meta: { title: '会员级别管理',  }
      },
      {
        path: 'leaves',
        name: 'leaves',
        component: () => import('@/views/sys/leaves/index'),
        meta: { title: '留言管理',  },
      },
    ]
  },

  {
    path: '/sys-information',
    component: Layout,
    meta: { title: '资讯管理', icon: 'el-icon-eleme', roles: ['5'] },
    children: [
      {
        path: 'information',
        name: 'information',
        component: () => import('@/views/sys/information/index'),
        meta: { title: '资讯管理',  }
      },
      {
        path: 'information/add',
        name: 'add',
        component: () => import('@/views/sys/information/add'),
        meta: { title: '添加资讯',  },
        hidden: true
      },
      {
        path: 'information/edit/:id(\\d+)',
        name: 'edit',
        component: () => import('@/views/sys/information/edit'),
        meta: { title: '编辑资讯',  },
        hidden: true
      },
      {
        path: 'information/details/:id(\\d+)',
        name: 'details',
        component: () => import('@/views/sys/information/details'),
        meta: { title: '资讯详情',  },
        hidden: true
      },
      {
        path: 'notice',
        name: 'notice',
        component: () => import('@/views/sys/notice/index'),
        meta: { title: '公告管理',  }
      },
      {
        path: 'notice/add',
        name: 'add',
        component: () => import('@/views/sys/notice/add'),
        meta: { title: '添加公告',  },
        hidden: true
      },
      {
        path: 'notice/edit/:id(\\d+)',
        name: 'edit',
        component: () => import('@/views/sys/notice/edit'),
        meta: { title: '编辑公告',  },
        hidden: true
      },
      {
        path: 'notice/details/:id(\\d+)',
        name: 'details',
        component: () => import('@/views/sys/notice/details'),
        meta: { title: '公告详情',  },
        hidden: true
      },
    ]
  },

  {
    path: '/sys-services',
    component: Layout,
    meta: { title: '服务管理', icon: 'el-icon-bank-card', roles: ['5'] },
    children: [
      {
        path: 'servicesType',
        name: 'servicesType',
        component: () => import('@/views/sys/servicesType/index'),
        meta: { title: '服务类型管理',  },
      },
      {
        path: 'services',
        name: 'services',
        component: () => import('@/views/sys/services/index'),
        meta: { title: '服务管理',  },
      },
      {
        path: 'services/add',
        name: 'add',
        component: () => import('@/views/sys/services/add'),
        meta: { title: '添加服务',  },
        hidden: true
      },
      {
        path: 'services/edit/:id(\\d+)',
        name: 'edit',
        component: () => import('@/views/sys/services/edit'),
        meta: { title: '编辑服务',  },
        hidden: true
      },
      {
        path: 'services/details/:id(\\d+)',
        name: 'edit',
        component: () => import('@/views/sys/services/details'),
        meta: { title: '服务详情',  },
        hidden: true
      },
      {
        path: 'appointment',
        name: 'appointment',
        component: () => import('@/views/sys/appointment/index'),
        meta: { title: '订单管理',  },
      },
      {
        path: 'servicesComment',
        name: 'servicesComment',
        component: () => import('@/views/sys/servicesComment/index'),
        meta: { title: '评价管理',  },
      },
    ]
  },

  {
    path: '/sys-commodity',
    component: Layout,
    meta: { title: '产品管理', icon: 'el-icon-s-operation', roles: ['5'] },
    children: [
      {
        path: 'category',
        name: 'category',
        component: () => import('@/views/sys/category/index'),
        meta: { title: '产品分类管理',  }
      },
      {
        path: 'commodity',
        name: 'commodity',
        component: () => import('@/views/sys/commodity/index'),
        meta: { title: '产品管理',  }
      },
      {
        path: 'commodity/add',
        name: 'add',
        component: () => import('@/views/sys/commodity/add'),
        meta: { title: '添加产品',  },
        hidden: true
      },
      {
        path: 'commodity/edit/:id(\\d+)',
        name: 'edit',
        component: () => import('@/views/sys/commodity/edit'),
        meta: { title: '编辑产品',  },
        hidden: true
      },
      {
        path: 'commodity/details/:id(\\d+)',
        name: 'edit',
        component: () => import('@/views/sys/commodity/details'),
        meta: { title: '产品详情',  },
        hidden: true
      },
      {
        path: 'commodityOrders',
        name: 'commodityOrders',
        component: () => import('@/views/sys/commodityOrders/index'),
        meta: { title: '兑换管理',  }
      },
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/home', hidden: true }
]

// 静态路由
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true
  },

  {
    path: '/register',
    component: () => import('@/views/register'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
